package com.qf.controller;

import com.qf.pojo.Medicalhistory;
import com.qf.service.MedicalhistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/medicalhistory")
public class MedicalhistoryController {
    @Autowired
    private MedicalhistoryService medicalhistoryService;

    @RequestMapping("/selectByRegistId")
    @ResponseBody
    public Medicalhistory selectByRegistId(@RequestParam("registId")String registId){
        Medicalhistory medicalhistory=new Medicalhistory();
        medicalhistory.setRegistId(registId);
        List<Medicalhistory> select = medicalhistoryService.select(medicalhistory);
        if(!select.isEmpty()){
            return select.get(0);
        }
        else
            return null;
    }
    @RequestMapping("/insert")
    @ResponseBody
    public String insert(@RequestBody Medicalhistory medicalhistory){
        Date date=new Date();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(date);
        medicalhistory.setAccidentDate(format);
        System.out.println(medicalhistory);
        int insert = medicalhistoryService.insert(medicalhistory);
        if(insert==1){
            return "success";
        }
        else return "error";
    }
}
